﻿<%@ Page Language="C#" AutoEventWireup="true" Culture="en-GB" CodeFile="Outstandings.aspx.cs" Inherits="Main_Reports_ServiceInvoice_InvoiceViews_Outstandings" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Outstanding Register</title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .gridheader
        {
            margin-left: 3px;
            margin-right: 3px;
        }
    </style>

    <script type="text/javascript" language="javascript">
        function checkdate() {
            if (document.getElementById("txtto").value == '') {
                alert('Specify To Date!');
                document.getElementById("txtto").focus();
                return false;
            }
        }
        function EnabledTabKey(id, e) {
            var keycode;
            if (window.event) {
                keycode = window.event.keyCode;
            }
            else if (e) {
                keycode = e.which;
            }
            else {
                return true;
            }

            if (keycode == 9) {
                // if is the tab key                
                return true;
            }
            else {
                return false;
            }
        }
        function Validation() {
            var flag = true;
            var txtTodate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (isDate(txtTodate) != true) {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");
            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }

            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {

                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }
    </script>

    <script type="text/javascript">
        function expandDetailsInGrid(imgId, grdId) {
            var imgelem = document.getElementById(imgId);
            var rowdetelem = document.getElementById(grdId);
            if (imgelem.alt == "plus") {
                imgelem.src = "../../../../Images/minus.png";
                imgelem.alt = "minus";

                    rowdetelem.style.display = "block";

            }
            else {
                imgelem.src = "../../../../Images/plus.png";
                imgelem.alt = "plus";
                rowdetelem.style.display = "none";
            }
            return false;
        }
        function printPartOfPage() {
            var printDiv = document.getElementById("pnlPrint").innerHTML;
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
            var printWindow = window.open(windowUrl, windowName, 'width=10,height=10');
            printWindow.document.write('<html><link rel="stylesheet" type="text/css" href="../../../../Styles/accounts.css" /><body>');
            printWindow.document.write(printDiv);
            printWindow.document.write("</body></html>");
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptmanager1" runat="server">
    </asp:ScriptManager>
    <asp:HiddenField ID="hidfinyear" runat="server" />
    <asp:HiddenField ID="hidToDate" runat="server" />
    <acc:heading ID="pagehead" runat="server" HeadingText="Outstandings" />
    <div style="width: 100%; margin-left: 20px;">
        <asp:HyperLink ID="hyperChangeDate" runat="server" NavigateUrl="#" Text="Change Date"></asp:HyperLink>&nbsp;&nbsp;&nbsp;<asp:HyperLink ID="hyplnkPrint" runat="server" NavigateUrl="#" onclick="return printPartOfPage();"
                        Text="Print"></asp:HyperLink>&nbsp;&nbsp;&nbsp;<asp:HyperLink ID="hyperMainMenu" runat="server" NavigateUrl="~/Main/Reports/ServiceInvoice/InvoiceViews/InvoiceView.aspx" Text="Main Menu"></asp:HyperLink>
        <br /><center>
            <b>
                <asp:Label ID="lblCompName2" runat="server"></asp:Label></b></center>
        <br />
        <center>
            <b>
                <asp:Label ID="lblMsg" runat="server"></asp:Label></b></center>
                <hr style="border:1px; color:#818181; width:100%" />
    </div>
   
    <br />
    <br />
    <asp:Panel ID="pnlChangeDate" runat="server" Width="350px" Height="160px" Style="display: none"
        CssClass="modalPopup">
        <div style="width: 70%; margin: 30px 15% 30px 15%;">
            <table>
                <tr>
                    <td>
                        Till Date
                    </td>
                    <td style="padding-left: 10px; padding-top:10px;">
                        <asp:TextBox ID="txtToDate" runat="server" CssClass="input" ToolTip="DD/MM/YYYY"
                            Width="100px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button ID="btnCangeDate" runat="server" CssClass="button" Text="Ok" OnClick="btnCangeDate_Click"
                            OnClientClick="return Validation();" />&nbsp;
                        <asp:Button ID="btncancel" runat="server" CssClass="button" Text="Cancel" />&nbsp;
                    </td>
                </tr>
            </table>
        </div>
    </asp:Panel>
    <ajaxToolkit:ModalPopupExtender ID="modalChangeDate" runat="server" CancelControlID="btncancel"
        TargetControlID="hyperChangeDate" PopupControlID="pnlChangeDate" BackgroundCssClass="modalBackground">
    </ajaxToolkit:ModalPopupExtender>
    <div style="padding-left:20px;">
    <center>
            <b>
                <asp:Label ID="Label1" runat="server"></asp:Label></b></center>
    <asp:DataList ID="DataList1" OnItemDataBound="DataList1_ItemBound" Width="1000px" ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="1px" ItemStyle-BorderColor="#818181" SelectedItemStyle-VerticalAlign="Top" runat="server">        
        <ItemTemplate>           
                <asp:ImageButton runat="server" ID="imgShow" ImageUrl="../../../../Images/plus.png" AlternateText="plus" />
                <asp:Label ID="lblAgeRange" runat="server" Text='<%#Eval("AgeRange") %>'></asp:Label>         
                <asp:GridView ID="grdDetails" OnRowDataBound="grdChild_RowDataBound" Width="100%" CssClass="gridview" AutoGenerateColumns="false" style="display:none ;margin-top:5px" runat="server">
                <Columns>                   
                    <asp:BoundField HeaderText="Reference" DataField="REFNO" ItemStyle-Width="8%" />
                    <asp:BoundField HeaderText="Bill No." DataField="VoucherNumber" ItemStyle-Width="8%" />
                    <asp:BoundField HeaderText="Date" DataField="Date" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width="10%" />
                    <asp:BoundField HeaderText="Customer Name" DataField="CustomerName" ItemStyle-Width="18%" />
                    <asp:BoundField HeaderText="Original Amt" DataField="Amount" ItemStyle-Width="12%" />
                    <asp:BoundField HeaderText="Pending Amt" DataField="RefAmt" ItemStyle-Width="12%" />
                    <asp:BoundField HeaderText="Due On" DataField="Dueon" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width="10%" />
                    <asp:BoundField HeaderText="Due Days" DataField="DueDays" ItemStyle-Width="8%" />
                    <asp:BoundField HeaderText="Remarks" DataField="Remarks" ItemStyle-Width="14%" />                    
                </Columns>
                </asp:GridView>
        </ItemTemplate>
    </asp:DataList>
    </div>
    <asp:Panel ID="pnlPrint" Width="98%" runat="server" Style="margin-left: 1%; display:none;">
        <center>
            <b>
                <asp:Label ID="lblCompName" runat="server"></asp:Label></b></center>
        <br />
        <center>
            <b>
                <asp:Label ID="lblMsg2" runat="server"></asp:Label></b></center>
        <br />
        <asp:DataList ID="DataList2" OnItemDataBound="DataList2_ItemBound" Width="98%" ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="1px" ItemStyle-BorderColor="#818181" SelectedItemStyle-VerticalAlign="Top" runat="server">        
        <ItemTemplate>           
                <b><asp:Label ID="lblPrintAgeRange" runat="server" Text='<%#Eval("AgeRange") %>'></asp:Label></b><br />
                <asp:GridView ID="grdPrint" ShowFooter="true" OnRowDataBound="grdPrint_RowDataBound" Width="100%" CssClass="gridview" style="margin-bottom:5px;" AutoGenerateColumns="false" runat="server">
                <Columns>                   
                    <asp:BoundField HeaderText="Bill No." DataField="VoucherNumber" ItemStyle-Width="8%" />
                    <asp:BoundField HeaderText="Date" DataField="Date" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width="10%" />
                    <asp:BoundField HeaderText="Customer Name" DataField="CustomerName" ItemStyle-Width="18%" />
                    <asp:BoundField HeaderText="Original Amt" DataField="Amount" ItemStyle-Width="12%" />
                    <asp:BoundField HeaderText="Pending Amt" DataField="RefAmt" ItemStyle-Width="12%" />                    
                </Columns>
                </asp:GridView>
        </ItemTemplate>
    </asp:DataList>
            </asp:Panel>
    </form>
</body>
</html>       
       